package com.tanhua.server.controller;

import com.tanhua.model.vo.ContactVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 根据环信id 查询用户信息
     * @return
     */
    @GetMapping("/userinfo")
    public ResponseEntity getUserInfo(String huanxinId){
        UserInfoVo userInfoVo = messagesService.findUserByHuanxinUser(huanxinId);
        return ResponseEntity.ok(userInfoVo);
    }

    /**
     * 联系人添加
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity addContacts(@RequestBody Map<String, String> param){
        Long userId = Long.valueOf(param.get("userId").toString());  // 佳人id
        messagesService.addContacts(userId);
        return ResponseEntity.ok(null);
    }

    /**
     * 分页查询联系人列表
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity contactsList(@RequestParam(value = "page",defaultValue = "1") Long page,
                                       @RequestParam(value = "pagesize",defaultValue = "10") Long pageSize,
                                       String keyword){
        PageResult<ContactVo> contactVoPageResult = messagesService.contactsList(page,pageSize,keyword);
        return ResponseEntity.ok(contactVoPageResult);
    }

}
